package MyCircularQueue;

public class MyCircularQueue {

    public int[] arr;

    public int first;
    public int rear;

    public int usedSize;

    public int fullSize;

    public MyCircularQueue(int k) {
        arr = new int[k];
        fullSize = k;
    }

    public boolean enQueue(int value) {
        if (isFull()) {
            return false;
        }

        arr[rear] = value;
        rear = (rear + 1) % fullSize;
        usedSize++;

        return true;
    }

    public boolean deQueue() {
        if (isEmpty()) {
            return false;
        }

        first = (first + 1) % fullSize;

        usedSize--;
        return true;
    }

    public int Front() {
        if (isEmpty()) {
            return -1;
        }

        return arr[first];
    }

    public int Rear() {
        if (isEmpty()) {
            return -1;
        }
        if (rear == 0) {
            return arr[fullSize - 1];
        } else {
            return arr[rear - 1];
        }

    }

    public boolean isEmpty() {
        return usedSize == 0;
    }

    public boolean isFull() {
        return usedSize == fullSize;
    }
}
